////用户搜索
 
 (function($){
    $.searuser=function(page,keywords){
        var page = arguments[0]?arguments[0] : 1;
     var keywords=arguments[1]?arguments[1] :'';
     var time=$("input[name='addtime']").val();
     var end=$("input[name='endtime']").val();
     $.ajax({
        type:'POST',
        url:"/admin.php/Home/User/Search",
        data:{"page":page,"keywords":keywords,"addtime":time,"endtime":end},
        dataType:"json",
        success:function(message)
        {/////解析json数据
          
           if(message.status)
           {  
             var $page=message.pagearr;
             var $users=message.users;
              var $tbody=$('<tbody></tbody>');
              var $string='';
              ////遍历数据
              $.each($users,function(key,user){

                
                  $string+='<tr><td><input type="checkbox"></td>';
                  $string+="<td>"+user.uid+"</td>";
                  $string+="<td>"+user.uname+"</td>";
                  $string+="<td>"+user.nickname+"</td>";
                  $string+="<td>"+user.phone+"</td>";
                  $string+="<td>"+user.addtime+"</td>";
                  $string+="<td>"
                  if(user.isshop==0){
                         $string+='&nbsp;<span class=am-icon-pencil-square-o> </span><a href="javascript:void(0)" class="shop" value='+user.uid+'> 否 </a>';
                  }else{
                      $string+='&nbsp;<span class=am-icon-pencil-square-o> </span><a href="javascript:void(0)" class="shop" value='+user.uid+' > 是 </a>';
                  }
                   $string+='<input name=isshop_'+user.uid+'  type=hidden value='+user.isshop+' >';
                   $string+="</td></tr>";
                 })////遍历数据end
                   $tbody.append($string);
                  $($tbody).replaceAll(".usertable tbody");
              //替换分页
               $(".count").html($page.count);
              $(".currentpage").html($page.page);
              $("#pagesize").val($page.pagesize);
              $('.prepage').attr('value',$page.prevpage);
              $('.nexpage').attr('value',$page.nextpage);
              $('.laspage').attr('value',$page.pagetotal);
              $('.pagetotal').html($page.pagetotal);
              
           }else
           {
            $('tbody').html('暂无数据');     
           }
        }
     })

    }
 })(jQuery);
$('.Usersear').click(function(){
    var keywords=$("input[name='keywords']").val();
     $.searuser(1,keywords);
     return false;
  });
////是否设置为分销商
$(".shop").click(function(){
  var usernode=$(this);
  var uid=$(this).attr("value");
    var state=$("input[name=isshop_"+uid+"]").val();
    if(state==0){
      var re=confirm("确定成为分销商");
      if(!re){
        return false;
      }
    }
    if(state==1)
    {
      var res=confirm("确定取消分销商资格") ;
      if(!res){
        return false;
      }
    }
    $.ajax({
      type:'GET',
      data:{"uid":uid,"state":state},
       url:"/admin.php/Home/User/trader",
        dataType:"json",
        success:function(data){
          if(data.status)
    {
     alert(data.msg);
     if(state==0){
       
      usernode.text("是");
      $("input[name=isshop_"+id+"]").val(1);


     }else{

      usernode.text("否");
       $("input[name=isshop_"+id+"]").val(0);
     }
    }
          
        }
    })

})